package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.BaseInStoreDetailMapper;
import com.kaili.basic.mapper.BaseOutStoreDetailMapper;
import com.kaili.basic.pojo.dto.BaseInStoreDetailAddDto;
import com.kaili.basic.pojo.dto.BaseOutStoreDetailAddDTO;
import com.kaili.basic.pojo.entity.BaseInStoreDetailEntity;
import com.kaili.basic.pojo.entity.BaseOutStoreDetailEntity;
import com.kaili.basic.pojo.entity.BaseStoreStockEntity;
import com.kaili.basic.pojo.vo.BaseInStoreDetailVO;
import com.kaili.basic.service.BaseInStoreDetailService;
import com.kaili.basic.service.BaseOutStoreDeatailService;
import com.kaili.basic.service.BaseOutStoreService;
import com.kaili.basic.service.BaseStoreStockService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BaseOutStoreDetailServiceImpl extends ServiceImpl<BaseOutStoreDetailMapper, BaseOutStoreDetailEntity> implements BaseOutStoreDeatailService {

    @Autowired
    private BaseStoreStockService baseStoreStockService;

    @Override
    public void bathInsert(List<BaseOutStoreDetailAddDTO> detailList, String orderNo) {
        List<BaseOutStoreDetailEntity> list=new ArrayList<>();
        for(BaseOutStoreDetailAddDTO detailAdd:detailList){
            BaseOutStoreDetailEntity detailEntity=new BaseOutStoreDetailEntity();
            BeanUtils.copyProperties(detailAdd,detailEntity);
            detailEntity.setOrderNo(orderNo);
            detailEntity.setCreateTime(new Date());
            detailEntity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
            BaseStoreStockEntity stock = baseStoreStockService.selectById(detailAdd.getStoreStockId());
            //设置出库明细信息
            detailEntity.setLocationId(stock.getLocationId());
            detailEntity.setStoreId(stock.getStoreId());
            detailEntity.setProductId(stock.getProductId());
            detailEntity.setBatch(stock.getBatch());
            detailEntity.setDeadTime(stock.getDeadTime());
            list.add(detailEntity);
        }
        this.insertBatch(list);
    }
}
